from fastapi import FastAPI, Body
from typing import Optional
from pydantic import BaseModel

app = FastAPI(title="大标题", description="整体描述")


class JiekouCanshuJieshi(BaseModel):
    para1: str
    para2: int
    para3: Optional[str] = None
    para4: Optional[str] = "自己添加"
    para5: Optional[int] = 110


@app.post(path="/api1", summary="接口1注释", description="接口1描述", tags=["前端"])
def fun1():
    return 1


@app.post(path="/api2", summary="接口2注释", description="接口2描述", tags=["前端"])
def fun2():
    return 2


@app.post(path="/api3", summary="接口3注释", description="接口3描述", tags=["后端"])
def fun3():
    return 3


@app.post(path="/api4", summary="接口4注释", description="接口4描述", tags=["后端"])
def fun4():
    return 4


@app.post(path="/api5", summary="接口参数注释1", description="接口5描述", tags=["评论交流"])
def fun5(inputData: JiekouCanshuJieshi):
    return inputData


@app.post(path="/api6", summary="接口参数注释2", description="接口6描述", tags=["评论交流"])
def fun6(
    inputData: JiekouCanshuJieshi = Body(
        ...,
        example={
            "para1": "必填，格式要求是字符串",
            "para2": "必填,格式要求是整型",
            "para3": "选填，格式要求是字符串,默认值是None",
            "para4": "选填，格式要求是字符串,默认值是'自己添加'",
            "para5": "选填，格式要求是整型,默认值是110",
        },
    )
):
    return inputData


if __name__ == "__main__":
    import uvicorn

    uvicorn.run("1:app", host="0.0.0.0", port=4000, reload=True)
